﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Dragon.Prototype1.Infrastructure.Controls;
using System.IO;
using System.Web.Mvc;

namespace Dragon.Prototype1.Infrastructure.FormBuilder
{
    public class jQueryFormBuilder :jQueryControl
    {

        public bool AutoTabIndex
        {
            get;
            set;
        }

        List<FormGroup> formGroupCollection = new List<FormGroup>();
        public List<FormGroup> Groups
        {
            get { return formGroupCollection; }
        }

        public override void RenderContents(HtmlTextWriter writer)
        {
            foreach (FormGroup fg in formGroupCollection)
            {
                fg.Render(writer);
            }
        }

        public override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);

            this.RenderJavaScriptStart(writer);
            this.RenderJavaScriptContents(writer);
            this.RenderJavaScriptEnd(writer);
        }

        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Div;
            }
        }

        public override void RenderJavaScriptContents(HtmlTextWriter writer)
        {
            foreach (FormGroup group in formGroupCollection)
            {
                group.RenderJavaScriptContents(writer);
            }
        }
        public string Display()
        {
            StringWriter stringWriter = new StringWriter();
            HtmlTextWriter output = new HtmlTextWriter(stringWriter);
            this.Render(output);
            return stringWriter.ToString();
        }
    }
}
